const { Application } = require('ee-core');
const {
  app,
  BrowserWindow,
  ipcRenderer,
  ipcMain,
  globalShortcut
} = require('electron');
const { flatMap } = require('lodash');

class Index extends Application {

  constructor() {
    super();
    // this === eeApp;
  }

  /**
   * core app have been loaded
   */
  async ready() {
    // do some things

  }

  /**
   * electron app ready
   */
  async electronAppReady() {
    // do some things
  }

  /**
   * main window have been loaded
   */
  async windowReady() {
    // console.log( '9999', this.electron.mainWindow)
    // do some things
    // 延迟加载，无白屏
    const winOpt = this.config.windowsOption;
    this.electron.mainWindow.webContents.openDevTools()
    if (winOpt.show == false) {
      const win = this.electron.mainWindow;
      win.once('ready-to-show', () => {
        win.show();
        win.focus();
      })
    }
    globalShortcut.register('ESC', ()=> {
      console.log("123",this.electron.mainWindow)
      this.electron.mainWindow.setFullScreen(false);
    })
  
  }

  /**
   * before app close
   */
  async beforeClose() {
    // do some things


  }


  windowMin() {
    console.log("111", this.electron.mainWindow)
    this.electron.mainWindow.minimize()
  }

  windowMax() {

    this.electron.mainWindow.setFullScreen(true)
    // if (this.electron.mainWindow.setFullScreen(true)) {
    //   this.electron.mainWindow.restore();
    // } else {
    //   this.electron.mainWindow.setFullScreen(true)
    // }
  }

  wondowClose() {

    this.electron.mainWindow.close()
  }

}







//登录窗口最小化
ipcMain.on('window-min', function () {
  console.log('min2')
  const mainWindow = new Index()
  mainWindow.windowMin()
  // mainWindow.minimize();
})
//登录窗口最大化
ipcMain.on('window-max', function () {
  console.log('max1')
  const mainWindow = new Index()
  mainWindow.windowMax()
  // if (mainWindow.isMaximized()) {
  //   mainWindow.restore();
  // } else {
  //   mainWindow.maximize();
  // }
})
//关闭窗口
ipcMain.on('window-close', function () {
  console.log('close111')
  app.quit()
})
Index.toString = () => '[class Index]';
module.exports = Index;